package prop;

import java.beans.PropertyChangeSupport;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;

public class Test implements PropertyChangeListener{
	private String label = "cos";
	private String name = "cos";
	private PropertyChangeSupport pcs = new PropertyChangeSupport(this);

	public Test() {
		pcs.addPropertyChangeListener(this);
		//pcs.addPropertyChangeListener(label, this);
	}

	public void propertyChange(PropertyChangeEvent evt) {
		if (evt.getPropertyName().equals("setName")) {
			System.out.println("zmiana nazwy");
			label = evt.getNewValue().toString();
		}
	}

	public static void main(String[] args) {
		Test bean = new Test();
		System.out.println(bean.name);
		System.out.println(bean.label);
		bean.setName("nowe");
		System.out.println(bean.name);
		System.out.println(bean.label);
	}


	//~ --------------------------------------------- Bean's Getters and Setters

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
		pcs.firePropertyChange("setName", "", name);
	}
}